import { createRouter, createWebHistory } from "vue-router";
import Layui from "@/views/layout/index.vue";
import login from "@/views/login/index.vue";
import Category from "@/views/category/index.vue";
import SubCategory from "@/views/SubCategory/index.vue";
import Detail from "@/views/detail/index.vue";

const routes = [
  // 登录
  {
    path: "/login",
    name: "login",
    component: login,
  },
  {
    path: "/",
    name: "home",
    component: Layui,
    children: [
      {
        path: "/",
        component: () => import("@/views/home/index.vue"),
      },
      {
        path: "category/:id",
        component: Category,
      },
      // 二级面包屑
      {
        path: "/category/sub/:id",
        component: SubCategory,
      },
      // 详情页
      {
        path: "detail/:id",
        component: Detail,
      },
      // 购物车页面
      {
        path: "/cartList",
        component: () => import("@/views/CartList/index.vue"),
      },
    ],
  },
];

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  // 路由滚动行为定制
  scrollBehavior() {
    return {
      top: 0,
    };
  },
  routes,
});

export default router;
